//
//  AddFoundController.m
//  bmob
//
//  Created by hjl on 16/4/4.
//  Copyright © 2016年 hjl. All rights reserved.
//

#import "AddFoundController.h"
#import <BmobSDK/Bmob.h>
@interface AddFoundController ()
@property (weak, nonatomic) IBOutlet UITextField *titleTextField;
@property (weak, nonatomic) IBOutlet UITextField *phoneTextField;
@property (weak, nonatomic) IBOutlet UITextField *desTextField;
- (IBAction)save:(id)sender;
- (IBAction)back:(id)sender;
@end

@implementation AddFoundController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (IBAction)save:(id)sender {
    if ([self.titleTextField.text length] > 0 && [self.phoneTextField.text length] > 0 && [self.desTextField.text length] > 0) {
        
        NSString *className = @"Found";
        
        BmobObject *obj = [[BmobObject alloc] initWithClassName:className];
        
        
        [obj setObject:self.titleTextField.text forKey:@"title"];
        [obj setObject:self.phoneTextField.text forKey:@"phone"];
        [obj setObject:self.desTextField.text forKey:@"describe"];
        
        [obj saveInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
            
            if (!error) {
                NSLog(@"提交成功");
                // block
                if (_block) {
                    _block(obj);
                }
                
                [self.navigationController popViewControllerAnimated:YES];
            }
        }];
        
    }
    
}

- (IBAction)back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


@end
